package com.zyy.dept.controller;


import com.zyy.dept.entity.Dept;
import com.zyy.dept.service.DeptService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author zyy
 * @since 2023-02-07
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    private final DeptService deptService;

    public DeptController(DeptService deptService) {
        this.deptService = deptService;
    }

    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    public List<Dept> getAll() {
        return deptService.getAll();
    }

    @RequestMapping(value = "/get/{deptNo}", method = RequestMethod.GET)
    public Dept getByNo(@PathVariable long deptNo) {
        return deptService.getByNo(deptNo);
    }

    @RequestMapping(value = "/addDept", method = RequestMethod.POST)
    public Boolean addDept(@RequestBody Dept dept) {
        Integer integer = deptService.addDept(dept);
        if (integer == null || integer.intValue() < 1) {
            return false;
        }
        return true;
    }
}

